package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Travel;
import cn.wolfcode.wolf2w.query.TravelQueryObject;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.ITravelService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@RequestMapping("travel")
@Controller
public class TravelController {

    @Autowired
    private ITravelService travelService;

    /**
     * 页面展示
     * @param model
     * @param qo
     * @return
     */
    @RequestMapping("/list")
    public String list(Model model,@ModelAttribute("qo") TravelQueryObject qo){
        //查询页面数据
        Page page = travelService.query(qo);
        //分享数据到页面
        model.addAttribute("page", page);

        return "travel/list";
    }


    /**
     * 审核状态
     * @param id
     * @param state
     * @return
     */
    @RequestMapping("/audit")
    @ResponseBody
    public Object audit(String id, int state){

        travelService.audit(id,state);
        return JsonResult.success();
    }


    /**
     * 查看游记详细内容
     * @param id
     * @return
     */
    @RequestMapping("/getContentById")
    @ResponseBody
    public Object getContentById(String id){
        return JsonResult.success(travelService.get(id).getContent());
    }



}
